package szwolaiyun.paireach.com.szwolaizhuang.fragment;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import szwolaiyun.paireach.com.szwolaizhuang.R;
import szwolaiyun.paireach.com.szwolaizhuang.mode.MessageInfo;
import szwolaiyun.paireach.com.szwolaizhuang.util.MessageInfoUtil;

/**
 * Created by Administrator on 2016/7/21.
 */
public class MessageHistoryFragment extends Fragment implements AdapterView.OnItemClickListener {
    private View view;
    private Handler handler;
    private SimpleAdapter adapter;
    private ListView history_listview;
    List<HashMap<String ,String >>list;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        view=inflater.inflate(R.layout.fragment_message_history,null);
        initControl();
        return view;
    }

    public void setHandle(Handler handler){
        this.handler=handler;
    }
   private void initControl(){
       history_listview=(ListView)view.findViewById(R.id.message_history_listview);
       adapter=new SimpleAdapter(getActivity(),setData(),R.layout.item_message_history,new String[]{"info"},new int[]{R.id.history_text});
       history_listview.setAdapter(adapter);
       history_listview.setOnItemClickListener(this);
   }

    List<HashMap<String ,String >> setData(){
     list=new ArrayList<HashMap<String ,String >>();
        for(int i=0;i<10;i++){
            HashMap<String,String>map=new HashMap<>();
            map.put("info","11月10日我来运1.8.2版本更新，修改定位问题，做了相关内容的优化");
            map.put("title","7月20日我来装上线通告");
            list.add(map);
        }
        return list;
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        MessageInfo messageInfo=new MessageInfo();
        messageInfo.setTitle(list.get(position).get("title"));
        messageInfo.setInfo(list.get(position).get("info"));
        Message message=new Message();
        message.obj=messageInfo;
        message.what= MessageInfoUtil.TO_MESSAGE;
        handler.sendMessage(message);
    }
}
